package com.society.sgsc.dict.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.society.sgsc.dict.mapper.DictMapper;
import com.society.sgsc.dict.service.DictService;
import com.society.sgsc.entities.Dict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * sgsc
 * com.society.sgsc.dict.service.impl
 * 类功能描述
 *
 * @author 尘心
 * @date 2025/3/14 下午 02:19
 */
@Transactional//声明事务的
@Service
public class DictServiceImpl implements DictService {

    // 注入Mapper
    @Resource
    DictMapper dictMapper;
    @Override
    public int addDict(Dict dict) throws Exception {
        System.out.println("xxxxxxxxx>" + dict);
        return dictMapper.insert(dict);
    }

    @Override
    public Dict getDictInfoByDictType(String dictType) throws Exception {
        QueryWrapper<Dict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dict_type", dictType);
        return dictMapper.selectOne(queryWrapper);
    }

    @Override
    public int saveDict(Dict dict) throws Exception {
        return null == getDictInfoByDictType(dict.getDictType()) ? this.addDict(dict) : 0;
    }

    @Override
    public List<Dict> dicts() throws Exception {
        return dictMapper.selectList(null);
    }
}
